import BaseClass from "./BaseClass";
import { app } from "./lzbjpk_app";
const {ccclass, property} = cc._decorator;



@ccclass
export default class DBBaseClass extends BaseClass {
    isLoadDB: boolean;
    isSendLoadDB: boolean;

    ctor(){
		var argList = Array.prototype.slice.call(arguments);

		this.JS_Name = "DBBaseClass";
		this.Init.apply(this, argList);

		this.OnReload();

      
	}

	//下线初始化
	OnReload(){
		this.isLoadDB = false;
		this.isSendLoadDB = false;

		this.InitReload();
	}

	//加载数据
	LoadInitDB(headName, sendPack){
		if(this.isLoadDB){
			return
		}
		if(this.isSendLoadDB){
			return
		}
		this.isSendLoadDB = true;

		//发送请求初始化管理器数据
		app[app.subGameName + "_NetManager"]().SendPack(headName, sendPack, this.OnSuccessInitDBData.bind(this), this.OnFailInitDBData.bind(this));
	}

	//初始化请求回调
	OnSuccessInitDBData(serverPack){
		this.isLoadDB = true;
		this.OnInitData(serverPack);
	}

	//初始化请求失败回调
	OnFailInitDBData(failInfo){
		this.isLoadDB = false;
		this.isSendLoadDB = false;

		this.OnFailInitData(failInfo);
	}

	//-------------子类需要实现的函数-------------
	InitReload(){
		console.error("InitReload 必须实现");
	}

	OnInitData(serverPack){
		console.error("OnInitData 必须实现");
	}

	OnFailInitData(failInfo){
		console.error("OnFailInitData 必须实现");
	}
}
